<?php
class Warehouse_Model_ShelfClass
{

	private $_table;
	//Initalizing Db Table  
	public function __construct(){
		$this->_table = new Warehouse_Model_DbTable_ShelfClass();
	}
	
	public  function create($row){
 		return $this->_table->insert($row); 
	}
	
	public  function update($row,$id){
		$where = $this->_table->getAdapter()->quoteInto("wsc_id= ?", $id);
		return $this->_table->update($row, $where);
	}
		
	/**
	*Delete One Row
	*@param int $wsc_id 
	*@return boolean
	*/
	public function delete($id){
		$where = $this->_table->getAdapter()->quoteInto("wsc_id= ?", $id);
		return $this->_table->delete($where);
	}

    public function getByCondition($condition,$type='*',$orderby=array('wsc_id'),$pageSize=0,$page=1){
        $select = $this->_table->getAdapter()->select();
        $table = $this->_table->info('name');
        $select->from($table,$type);
        $select->where("1 =?",1);
		if(isset($condition["wsc_code"]) && $condition["wsc_code"]!=''){
            $select->where(" wsc_code = ?",$condition["wsc_code"]);
        }
		if(isset($condition["warehouse_id"]) && $condition["warehouse_id"]!=''){
            $select->where(" warehouse_id = ?",$condition["warehouse_id"]);
        }
		if(isset($condition["wsc_pallet"]) && $condition["wsc_pallet"]!=''){
            $select->where(" wsc_pallet = ?",$condition["wsc_pallet"]);
        }
		if(isset($condition["wsc_status"]) && $condition["wsc_status"]!=''){
            $select->where(" wsc_status = ?",$condition["wsc_status"]);
        }
        if('count(*)'==$type){
            return $this->_table->getAdapter()->fetchOne($select);
        }else{
            $select->order($orderby);
            if($pageSize>0 and $page>0)
            {
                $start =($page-1)*$pageSize;
                $select->limit($pageSize,$start);
            }
			$sql=$select->__toString();
		    return $this->_table->getAdapter()->fetchAll($sql);
        }
		
	}	
	
	/**
	*Get Rowset By Warehouse_Shelf 
	*@param string $ws_id 
	*@return Rowset
	*/
	public function getById($id){
		$where = $this->_table->getAdapter()->quoteInto('ws_id= ?', $id);
		return $this->_table->fetchRow($where);
	}
	
	public function getByfield($field=1,$value=1){
		$where = $this->_table->getAdapter()->quoteInto("{$field} = ?",$value);	
		return $this->_table->fetchRow($where);
	}
		
	
	
}